import get from '@dfeidao/atom-web/local/get';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';


interface Aa {
	role_no: string;
	id: string;
}
export default async function a008(fd: IFeidaoAiBrowserComponent) {


	const productid = get(fd, 'productid');
	const role = get(fd, 'role') as Aa;
	const role_no = role.role_no;
	const role_allot_id = get(fd, 'role_allot_id');
	if (!role_no) {
		error('角色编号为空');
		return;
	}
	if (!role_allot_id) {
		error('请选择权限组');
		return;
	}
	const query = {
		role_allot_id,
		role_no,
		productid
	};
	show_loading();
	const res = await nodejs<{ str: string; _ids: string }>('roler/zj-000004/s009', query);
	hide_loading();
	const c_boxs = fd.data.node.querySelectorAll('[data-feidao-name="list_checkbox"]:checked');
	const ids = Array.from(c_boxs).map((item) => {
		return item.getAttribute('data-feidao-id4');
	});
	let _id;
	const allot_group = get(fd, 'allot_group') as Aa;
	if (allot_group) {
		_id = allot_group.id;
	} else {
		_id = res._ids;
	}
	if (res.str === 'success') {
		fire('zj-000004', 'ec-003', role_allot_id, _id, ids);
		success('保存成功');
	} else {
		error('保存失败');
	}
}
